package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.RecInfoEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 接运信息表Provider
 *
 * @author generator
 * @date 2020-06-16 10:19
 */
public class RecInfoProvider {

    /**
     * 增加RecInfo
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-06-16 10:19
     */
    public String insertRecInfo(@Param("entity") RecInfoEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" rec_info ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" rec_code ", " #{entity.recCode,jdbcType=VARCHAR} ");
                VALUES(" contact ", " #{entity.contact,jdbcType=VARCHAR} ");
                VALUES(" contact_phone ", " #{entity.contactPhone,jdbcType=VARCHAR} ");
                VALUES(" contact_type ", " #{entity.contactType,jdbcType=TINYINT} ");
                VALUES(" dead_name ", " #{entity.deadName,jdbcType=VARCHAR} ");
                VALUES(" death_cause ", " #{entity.deathCause,jdbcType=VARCHAR} ");
                VALUES(" relation_code ", " #{entity.relationCode,jdbcType=SMALLINT} ");
                VALUES(" relation ", " #{entity.relation,jdbcType=VARCHAR} ");
                VALUES(" car_type_code ", " #{entity.carTypeCode,jdbcType=SMALLINT} ");
                VALUES(" car_type ", " #{entity.carType,jdbcType=VARCHAR} ");
                VALUES(" purpose_code ", " #{entity.purposeCode,jdbcType=SMALLINT} ");
                VALUES(" purpose ", " #{entity.purpose,jdbcType=VARCHAR} ");
                VALUES(" arrival_time ", " #{entity.arrivalTime,jdbcType=TIMESTAMP} ");
                VALUES(" rec_charge ", " #{entity.recCharge,jdbcType=DECIMAL} ");
                VALUES(" body_deposit_code ", " #{entity.bodyDepositCode,jdbcType=SMALLINT} ");
                VALUES(" body_deposit ", " #{entity.bodyDeposit,jdbcType=VARCHAR} ");
                VALUES(" address ", " #{entity.address,jdbcType=VARCHAR} ");
                VALUES(" sourceCode ", " #{entity.sourceCode,jdbcType=SMALLINT} ");
                VALUES(" source ", " #{entity.source,jdbcType=VARCHAR} ");
                VALUES(" task_state_code ", " #{entity.taskStateCode,jdbcType=SMALLINT} ");
                VALUES(" task_state ", " #{entity.taskState,jdbcType=VARCHAR} ");
                VALUES(" chargeRemark ", " #{entity.chargeRemark,jdbcType=VARCHAR} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" appId ", " #{entity.appId,jdbcType=VARCHAR} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改RecInfo
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-06-16 10:19
     */
    public String updateRecInfo(@Param("entity") RecInfoEntity entity) {
        return new SQL() {
            {
                UPDATE(" rec_info ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" rec_code = #{entity.recCode,jdbcType=VARCHAR} ");
                SET(" contact = #{entity.contact,jdbcType=VARCHAR} ");
                SET(" contact_phone = #{entity.contactPhone,jdbcType=VARCHAR} ");
                SET(" contact_type = #{entity.contactType,jdbcType=TINYINT} ");
                SET(" dead_name = #{entity.deadName,jdbcType=VARCHAR} ");
                SET(" death_cause = #{entity.deathCause,jdbcType=VARCHAR} ");
                SET(" relation_code = #{entity.relationCode,jdbcType=SMALLINT} ");
                SET(" relation = #{entity.relation,jdbcType=VARCHAR} ");
                SET(" car_type_code = #{entity.carTypeCode,jdbcType=SMALLINT} ");
                SET(" car_type = #{entity.carType,jdbcType=VARCHAR} ");
                SET(" purpose_code = #{entity.purposeCode,jdbcType=SMALLINT} ");
                SET(" purpose = #{entity.purpose,jdbcType=VARCHAR} ");
                SET(" arrival_time = #{entity.arrivalTime,jdbcType=TIMESTAMP} ");
                SET(" rec_charge = #{entity.recCharge,jdbcType=DECIMAL} ");
                SET(" body_deposit_code = #{entity.bodyDepositCode,jdbcType=SMALLINT} ");
                SET(" body_deposit = #{entity.bodyDeposit,jdbcType=VARCHAR} ");
                SET(" address = #{entity.address,jdbcType=VARCHAR} ");
                SET(" sourceCode = #{entity.sourceCode,jdbcType=SMALLINT} ");
                SET(" source = #{entity.source,jdbcType=VARCHAR} ");
                SET(" task_state_code = #{entity.taskStateCode,jdbcType=SMALLINT} ");
                SET(" task_state = #{entity.taskState,jdbcType=VARCHAR} ");
                SET(" chargeRemark = #{entity.chargeRemark,jdbcType=VARCHAR} ");
                SET(" remark = #{entity.remark} ");
                SET(" appId = #{entity.appId,jdbcType=VARCHAR} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询RecInfo列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-06-16 10:19
     */
    public String listRecInfo(@Param("entity") RecInfoEntity entity) {
        SQL list = new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,rec_code,contact,contact_phone,contact_type,dead_name,death_cause,relation_code,relation,car_type_code,car_type,purpose_code,purpose,arrival_time,rec_charge,body_deposit_code,body_deposit,address,sourceCode,source,task_state_code,task_state,chargeRemark,remark,appId,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" rec_info ");

                if (entity.getRecCode() != null) {
                    WHERE(" rec_code = #{entity.recCode,jdbcType=VARCHAR} ");
                }

                if (entity.getContact() != null) {
                    WHERE(" contact = #{entity.contact,jdbcType=VARCHAR} ");
                }

                if (entity.getContactPhone() != null) {
                    WHERE(" contact_phone = #{entity.contactPhone,jdbcType=VARCHAR} ");
                }

                if (entity.getContactType() != null) {
                    WHERE(" contact_type = #{entity.contactType,jdbcType=TINYINT} ");
                }

                if (entity.getDeadName() != null) {
                    WHERE(" dead_name = #{entity.deadName,jdbcType=VARCHAR} ");
                }

                if (entity.getDeathCause() != null) {
                    WHERE(" death_cause = #{entity.deathCause,jdbcType=VARCHAR} ");
                }

                if (entity.getRelationCode() != null) {
                    WHERE(" relation_code = #{entity.relationCode,jdbcType=SMALLINT} ");
                }

                if (entity.getRelation() != null) {
                    WHERE(" relation = #{entity.relation,jdbcType=VARCHAR} ");
                }

                if (entity.getCarTypeCode() != null) {
                    WHERE(" car_type_code = #{entity.carTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getCarType() != null) {
                    WHERE(" car_type = #{entity.carType,jdbcType=VARCHAR} ");
                }

                if (entity.getPurposeCode() != null) {
                    WHERE(" purpose_code = #{entity.purposeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getPurpose() != null) {
                    WHERE(" purpose = #{entity.purpose,jdbcType=VARCHAR} ");
                }

                if (entity.getArrivalTime() != null) {
                    WHERE(" arrival_time = #{entity.arrivalTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getRecCharge() != null) {
                    WHERE(" rec_charge = #{entity.recCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getBodyDepositCode() != null) {
                    WHERE(" body_deposit_code = #{entity.bodyDepositCode,jdbcType=SMALLINT} ");
                }

                if (entity.getBodyDeposit() != null) {
                    WHERE(" body_deposit = #{entity.bodyDeposit,jdbcType=VARCHAR} ");
                }

                if (entity.getAddress() != null) {
                    WHERE(" address = #{entity.address,jdbcType=VARCHAR} ");
                }

                if (entity.getSourceCode() != null) {
                    WHERE(" sourceCode = #{entity.sourceCode,jdbcType=SMALLINT} ");
                }

                if (entity.getSource() != null) {
                    WHERE(" source = #{entity.source,jdbcType=VARCHAR} ");
                }

                if (entity.getTaskStateCode() != null) {
                    WHERE(" task_state_code = #{entity.taskStateCode,jdbcType=SMALLINT} ");
                }

                if (entity.getTaskState() != null) {
                    WHERE(" task_state = #{entity.taskState,jdbcType=VARCHAR} ");
                }

                if (entity.getChargeRemark() != null) {
                    WHERE(" chargeRemark = #{entity.chargeRemark,jdbcType=VARCHAR} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getAppId() != null) {
                    WHERE(" appId = #{entity.appId,jdbcType=VARCHAR} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        };
        return list.toString();
    }
}